package com.eleadmin.order.controller;

import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.order.entity.Events;
import com.eleadmin.order.service.EventsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 事件记录
 * @author : Doman
 * @date : 2023-08-01 17:08:54
 * @version ：1.0
 */

@Api(tags = "事件记录")
@RestController
@RequestMapping("/api/order/events")
public class EventsController extends BaseController {

    @Autowired
    private EventsService eventsService;

    @PreAuthorize("hasAuthority('order:events:list')")
    //@ApiOperation("分页查询事件记录")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, Events events) throws Exception{
        return eventsService.list(page, events, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:events:list')")
    //@ApiOperation("查询全部事件记录")
    @GetMapping()
    public JsonResult list(Events events){
        return eventsService.list(events, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:events:list')")
    //@ApiOperation("根据id查询事件记录")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return eventsService.getById(id);
    }


    @PreAuthorize("hasAuthority('order:events:save')")
    @OperationLog
    @ApiOperation(value ="添加事件记录")
    @PostMapping()
    public JsonResult save(@RequestBody Events events) {
        try {
            return eventsService.save(events, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('order:events:update')")
    @OperationLog
    @ApiOperation(value ="修改事件记录")
    @PutMapping()
    public JsonResult update(@RequestBody Events events) {
        try {
            return eventsService.update(events, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:events:remove')")
    @OperationLog
    @ApiOperation(value ="删除事件记录")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return eventsService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
